package com.ecfront.test.dao;

import java.util.Date;
import java.util.Iterator;
import java.util.List;
import com.ecfront.dao.ReplyDAO;
import com.ecfront.pojo.Message;
import com.ecfront.pojo.Reply;
import com.ecfront.pojo.User;
import junit.framework.TestCase;

public class testReply extends TestCase {
	private static final ReplyDAO replyDao = (ReplyDAO)SpringUtilTest.getBean("ReplyDAO");
	//save or update test
	public void testSaveOrUpdate(){
		Reply reply = new Reply();
		reply.setContent("还有存活");
		reply.setDate(new Date());
		
		User user = new User();
		user.setId(1);
		reply.setUser(user);
		
		Message message = new Message();
		message.setId(1);
		reply.setMessage(message);
		
		replyDao.save(reply);
	}
	//findAll test
	public void testFindAll(){
		List list = replyDao.findAll();
		for(Iterator iter = list.iterator();iter.hasNext();){
			Reply reply = (Reply)iter.next();
			System.out.println(reply.getContent());
			
			System.out.println(reply.getMessage().getContent());
		}
	}
	//findById test
	public void testFindById(){
		Reply reply = replyDao.findById(1);
		System.out.println(reply.getContent());
		
		System.out.println(reply.getMessage().getContent());
		System.out.println(reply.getUser().getName());
	}
	//deltet test
	public void testDel(){
		Reply reply = new Reply();
		reply.setId(1);
		
		replyDao.delete(reply);
	}
	//property test
	public void testProperty(){
		List list = replyDao.findByRcontent("还有存活");
		for(Iterator iter = list.iterator();iter.hasNext();){
			Reply reply = (Reply)iter.next();
			System.out.println(reply.getContent());
			
			System.out.println(reply.getMessage().getContent());
		}
	}
}
